<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script type="text/javascript">
    $(function () {
        $('#framework_menu_treegrid1').tree({
            url: '${pageContext.request.contextPath}/systemManagerAction!menulist.action?roleid=${roleid}',
            idField: 'id',
            treeField: 'text',
            parentField: 'pid',
            fitColumns: true,
            border: false,
            checkbox: true,
            singleSelect: false,
            onLoadSuccess: function(node, data){
                check(data);
            }
        });

        function check(data){
            if(data == null){
                return;
            }

            if(data instanceof Array){
                $.each(data, function(index, item){
                    var node = $('#framework_menu_treegrid1').tree('find', item.id);
                    if(node == null){
                        return;
                    }

                    var children = $('#framework_menu_treegrid1').tree('getChildren', node.target);
                    if(children == null || children.length == 0){
                        console.info(item);
                        console.info(item.status);
                        if(item.attributes.status){
                            $('#framework_menu_treegrid1').tree('check', node.target);
                        }
                    }else{
                        $.each(children, function(index1, item1){
                            check(item1);
                        });
                    }
                });
            }else{
                var node = $('#framework_menu_treegrid1').tree('find', data.id);
                if(node == null){
                    return;
                }

                var children = $('#framework_menu_treegrid1').tree('getChildren', node.target);
                if(children == null || children.length == 0){
                    console.info(data);
                    console.info(data.status);
                    if(data.attributes.status){
                        $('#framework_menu_treegrid1').tree('check', node.target);
                    }
                }else{
                    $.each(children, function(index1, item1){
                        check(item1);
                    });
                }
            }

        }
    });
</script>

<table id="framework_menu_treegrid1"></table>